﻿using System;
using System.Threading;

namespace _20170206_Game_1_1
{
    class GameNode : DynamicGameObject
    {
        private static Random r = new Random();
        private ConsoleColor color;

        public GameNode(int x, int y, char symbol) : base(x, y, symbol)
        {
            color = (ConsoleColor)r.Next(1, 15);
        }


        public void MoveUp() { Y--; }

        public void MoveDown() { Y++; }

        public void MoveLeft() { X--; }

        public void MoveRight() { X++; }

        public override void Draw()
        {
            Console.SetCursorPosition(X, Y);
            Console.ForegroundColor = color;
            Console.Write(Symbol);
        }

        private void Draw(ConsoleColor c)
        {
            Console.SetCursorPosition(X, Y);
            Console.ForegroundColor = c;
            Console.Write(Symbol);
        }

        public override void Clear()
        {
            Console.SetCursorPosition(X, Y);
            Console.Write(' ');
        }

        public void SetRainbowColor()
        {
            for(int i = 0; i < 16; i++)
            {
                Console.ForegroundColor = color;
                
                Draw((ConsoleColor)i);
                Thread.Sleep(50);
            }
            Clear();
            Draw();
        }

        public override string ToString()
        {
            return string.Format("({0}, {1})", X, Y);
        }

    }
}